/**
 * 档案归还
 */
import React from "react";
import PropTypes from "prop-types";
import { routerRedux } from "dva/router";
import { connect } from "dva";
import { Row, Col, Button, Tabs } from "antd";
import Application from "./application";
import MyReturn from "./my";
import Checked from "./checked";
import Checking from "./checking";
import Details from './details'

const TabPane = Tabs.TabPane;
const HomePage = ({ location, dispatch, loading, returns,fileChange }) => {
  const permissions = sessionStorage.getItem("permissions")
  const { list, pagination, info, showDetails,currentItem,menus,modalVisibleReturn  } = returns;  
  const { userList } = fileChange;
  const showMenus = id => {
    dispatch({
      type:"returns/showMenus",
      payload:id
    })
  }
  const callback = key => {
    dispatch({
      type: "returns/stateAndType",
      payload: { operatingState: key, operatingType: 1 }
    });
    dispatch({
      type: "returns/query",
      payload: { page: 1, pageSize: 10 }
    });
    showMenus(key)
  };
  const detailsProps = {
    info,
    onComponent(){
    		dispatch({
	      type: "returns/stateAndType",
	      payload: { operatingState: 0, operatingType: 1 }
	    });
    },
    showList() {
      dispatch({
        type: "returns/showList",
        payload: {}
      });
    },
	onEdit(payload){
		dispatch({
			type:'returns/detailsUpdate',
			payload:{
				...payload
			}
		})
  },
  
  };    
  const ApplicationProps = {
    list,
    pagination, 
    currentItem, 
    userList,
    menus,
    dispatch,
    loading,
    modalVisibleReturn,
    getList(params){
      dispatch({
        type:"returns/query",
        payload:{...params}
      })
    },
    
  }
  const CheckingProps = {
    list, 
    pagination,
    info, 
    showDetails,
    menus,
    getList(params){
      dispatch({
        type:"returns/query",
        payload:{...params}
      })
    },
  }
  return (
    <div className="content-inner" style={{padding:0}}>
    {showDetails ? (
        <Details {...detailsProps} />
      ) : (
      <Tabs defaultActiveKey={menus} onChange={callback}>
        {permissions.indexOf("borrowManager:return:apply") != -1 ?
        <TabPane tab="归还申请" key="0">
          <Application {...ApplicationProps}/>
        </TabPane>
        :""}

        {permissions.indexOf("borrowManager:return:apply") != -1 ?
        <TabPane tab="我的归还" key="1">
          <MyReturn />
        </TabPane>
        :""}

        {permissions.indexOf("borrowManager:return:checked") != -1 ?
        <TabPane tab="待审核" key="2">
          <Checking {...CheckingProps}/>
        </TabPane>
        :""}

        {permissions.indexOf("borrowManager:return:checked") != -1 ?
        <TabPane tab="已审核" key="3">
          <Checked />
        </TabPane>
        :""}
      </Tabs>
      )}
    </div>
  );
};

HomePage.propTypes = {
  returns: PropTypes.object,
  location: PropTypes.object,
  dispatch: PropTypes.func,
  loading: PropTypes.object
};

export default connect(({ loading, returns,fileChange }) => ({ loading, returns, fileChange }))(
  HomePage
);
